package com.example.meituan.activity.user;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.example.meituan.R;
import com.example.meituan.activity.Message;
import com.example.meituan.activity.MessageAdapter;
import com.example.meituan.activity.bean.AdminBean;
import com.example.meituan.activity.bean.TalkBean;
import com.example.meituan.dao.AdminDao;
import com.example.meituan.dao.TalkDao;

import java.util.ArrayList;
import java.util.List;

public class MessageViewActivity extends AppCompatActivity {
    AdminBean adminBean;
    List<TalkBean> talkBeans;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_message_view);
        Intent intent = getIntent();
        adminBean = AdminDao.getUserInfo(MessageViewActivity.this);
        List<Message> messages = new ArrayList<>();;
        if (intent != null) {
            String value = intent.getStringExtra("userId");
            String value1 = intent.getStringExtra("businessId");
            String value3 = intent.getStringExtra("ifuserId");
            talkBeans = TalkDao.getAllTalksById(value, value1);
            for (TalkBean talkBean : talkBeans) {
                boolean is = true;
                if (value3 == "user" && talkBean.getIfByme() == 0) {
                    is = false;
                }
                if (value3 == "bussiness" && talkBean.getIfByme() == 1) {
                    is = false;
                }
                messages.add(new Message(talkBean.getTalk(), is));
            }
        }
        androidx.recyclerview.widget.RecyclerView recyclerView = findViewById(R.id.recycler_view);

        MessageAdapter adapter = new MessageAdapter(messages, this);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(adapter);
        adapter.notifyDataSetChanged();
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        TextView back=findViewById(R.id.message_vie_back);
    }
}